Skip to content

Conversation

@SarahFrench
Copy link
Member

@SarahFrench SarahFrench commented Oct 31, 2025

(Stacked on top of #37790, due to needing simple6 implementations of PSS for E2E testing)

This PR introduces a bunch of testing to show that the workspace commands work in combination with pluggable state storage. There is both an integration test and an E2E test showing that PSS can be used in the context of this sequence of actions:

  • Running init to create a default workspace
  • Creating a custom workspace
  • Listing all workspaces present
  • Selecting a different workspace
  • Showing the selected workspace
  • Deleting a workspace

In this PR I also updated how workspace new is implemented. This new code comment explains how the command previously achieved creating a new workspace:

// Create the new workspace
//
// In local, remote and remote-state backends obtaining a state manager
// creates an empty state file for the new workspace as a side-effect.
//
// The cloud backend also has logic in StateMgr for creating projects and
// workspaces if they don't already exist.
sMgr, sDiags := b.StateMgr(workspace)

Pluggable state stores intentionally don't have side-effects in the same way, and instead Terraform is expected to create the state file explicitly. I've updated the workspace new command to identify when PSS is in use and to only attempt to create the state file when that's the case. Due to this there isn't an issue of state files being 'created twice' etc when PSS isn't in use.

Target Release

1.15.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@SarahFrench SarahFrench force-pushed the pss/add-builtin-inmem-state-storage-implementation branch from 727ae19 to 8f77b19 Compare November 3, 2025 11:05
@SarahFrench SarahFrench force-pushed the pss/make-worspace-new-work-with-pss branch from 3226e68 to 345fef9 Compare November 3, 2025 11:06
@SarahFrench SarahFrench added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Nov 3, 2025
@SarahFrench SarahFrench force-pushed the pss/add-builtin-inmem-state-storage-implementation branch from 8f77b19 to 316d5b5 Compare November 6, 2025 12:40
@SarahFrench SarahFrench force-pushed the pss/make-worspace-new-work-with-pss branch 2 times, most recently from af8745d to 1e07af1 Compare November 7, 2025 11:24
Comment on lines 1842 to 1845
protoReq := &proto6.DeleteState_Request{
TypeName: r.TypeName,
StateId: r.StateId,
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a bug during this work 🐛

@SarahFrench SarahFrench changed the title Update the workspace new subcommand to work with PSS, add E2E test. PSS: Update the workspace new subcommand to work with PSS, add E2E and integration tests for using workspace commands with PSS. Nov 7, 2025
@SarahFrench SarahFrench force-pushed the pss/make-worspace-new-work-with-pss branch from 55a606d to 734e6fd Compare November 11, 2025 14:48
Base automatically changed from pss/add-builtin-inmem-state-storage-implementation to main November 11, 2025 15:30
@SarahFrench SarahFrench force-pushed the pss/make-worspace-new-work-with-pss branch from 734e6fd to 55de3b2 Compare November 11, 2025 15:32
@SarahFrench SarahFrench force-pushed the pss/make-worspace-new-work-with-pss branch from 55de3b2 to b8f9088 Compare November 11, 2025 15:36
@SarahFrench SarahFrench marked this pull request as ready for review November 11, 2025 15:38
@SarahFrench SarahFrench requested a review from a team as a code owner November 11, 2025 15:38
"github.com/hashicorp/terraform/internal/states/statemgr"
)

func TestWorkspace_allCommands_pluggableStateStore(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote the E2E test for all the workspace commands and then worried that an integration test would be sufficient. After writing an integration test equivalent I realised that the bug I found was only discovered due to adding the E2E test, so the E2E test definitely has value being there.

At this point I'm unsure about whether to keep both tests or to only keep the E2E test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog-needed Add this to your PR if the change does not require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant